<?php
require_once "HTTP/Request.php";

class HttpRequest {
	
	private $req = null;
	
	public function __construct($url = "") {
		$this->req =& new HTTP_Request($url);
      
        return true;
    }
    
    public function setRequestUrl($url) {
    	$this->req->setURL($url);
    }
    
    public function setAuthentication($user_name = "", $password = "") {
    	$this->req->setBasicAuth($user_name, $password);
    }
    
    public function setRequestMethod($method) {
    	$this->req->setMethod($method);
    }
    
    public function setRequestData($args) {
    	if ($args != null) {
            foreach ($args as $key => $value) {
                $this->req->addPostData($key, $value);
            }
        }
    }
    
    public function sendRequest() {
        $this->response = $this->req->sendRequest();

        if (PEAR::isError($this->response)) {
        	// need a better way to communicate errors
            echo $this->response->getMessage();
            die();
        } else {
            $this->responseBody = $this->req->getResponseBody();
        }
    }

    public function getResponse() {
        return $this->responseBody;
    }
}
?>